import Taro, { Component } from '@tarojs/taro'
import classNames from 'classnames'
import PropsType from 'prop-types'
import { AtAccordion, AtButton } from 'taro-ui'
import { View, Text } from '@tarojs/components'
import '../styles/userlist.scss'

export default class UserlistBox extends Component {

    handleClick() {
        this.props.handleClick && this.props.handleClick(...arguments)
    }
    onHandleFirst() {
        this.props.onHandleFirst && this.props.onHandleFirst(...arguments)
    }
    onHandleSecode() {
        this.props.onHandleSecode && this.props.onHandleSecode(...arguments)
    }
    onHandleThree() {
        this.props.onHandleThree && this.props.onHandleThree(...arguments)
    }
    render() {
        const {
            className,
            list
        } = this.props
        return (
            <View className={classNames('b_userlist', className)}>
                {
                    list.map((item, i) => {
                        return <View className='b_userlist__item'>
                            <AtAccordion open={item.open} key={i} title={item.title} onClick={this.handleClick.bind(this, i)}>
                                <View className='b_userlist__item_content'>
                                    {
                                        item.list && <View className='info_list'>
                                            {
                                                item.list && item.list.map((_item, key) => {
                                                    return <View className='info_list__item' key={key}>
                                                        <View className='info_list__item_left'>{_item.text}</View>
                                                        <View className='info_list__item_right'>{_item.name}</View>
                                                    </View>
                                                })
                                            }

                                        </View>
                                    }

                                    <View className='info_btn'>
                                        <AtButton onClick={this.onHandleFirst.bind(this, item)}>电话联系</AtButton>
                                        <AtButton onClick={this.onHandleSecode.bind(this, item)}>私聊联系</AtButton>
                                        <AtButton onClick={this.onHandleThree.bind(this, item)}>发起订金担保</AtButton>
                                    </View>
                                </View>
                            </AtAccordion>
                            <View className='b_userlist__item_money'>{item.money}</View>
                        </View>
                    })
                }
            </View>
        )
    }
}


UserlistBox.defaultProps = {
    className: '',
    list: [],
    handleClick: () => { },
    onHandleFirst: () => { },
    onHandleSecode: () => { },
    onHandleThree: () => { }
}

UserlistBox.PropsType = {
    className: PropsType.oneOfType[PropsType.string, PropsType.object],
    list: PropsType.array,
    handleClick: PropsType.func,
    onHandleFirst: PropsType.func,
    onHandleSecode: PropsType.func,
    onHandleThree: PropsType.func
}